sap.ui.define([
	"sap/ui/core/mvc/Controller",
	"sap/ui/model/json/JSONModel",
	"../model/formatter",
	"sap/ui/model/Filter",
	"sap/ui/model/FilterOperator"
], (Controller, JSONModel, formatter, Filter, FilterOperator) => {
	"use strict";

	return Controller.extend("ui5.walkthrough.controller.InvoiceList", {
		formatter: formatter,
		onInit() {
			const oViewModel = new JSONModel({
				currency: "EUR"
                // currency: "JPY"
			});
			this.getView().setModel(oViewModel, "view");
		},

		onSearchFieldSearch(oEvent) {
			// build filter array
			const aFilter = [];
			const sQuery = oEvent.getParameter("query");
			// 获取输入框中的输入
			if (sQuery) {
				aFilter.push(new Filter("ProductName", FilterOperator.Contains, sQuery));
				// 筛选的是变量"ProductName",筛选方法为包含
				// aFilter.push(new Filter("Status", FilterOperator.Contains, sQuery));
			}
			console.log(aFilter);

			// filter binding
			const oList = this.byId("idInvoicesList");
			const oBinding = oList.getBinding("items");
			oBinding.filter(aFilter);
		},

		onExtendedPriceObjectListItemPress(oEvent) {
			// 路由跳转
			const oItem = oEvent.getSource();
			const oRouter = this.getOwnerComponent().getRouter();
			
			// console.log(oItem.getBindingContext("invoice"));
			// console.log(oItem.getBindingContext("invoiceRemote"));
			oRouter.navTo("detail", {
				invoicePath: window.encodeURIComponent(oItem.getBindingContext("invoiceRemote").getPath().substr(1))
			});
		}
	});
});